<?php
/* wwwschool project

Copyright (C) 2009  Phillip Aldridge
Email : info@imi21.com
Web site http://www.imi21.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


/**
 *  File : listStudentScoring.php
 *  called only via ajax 
 *  List the scores of student for the content accessed
 *  @ $_POST['id'] selective listing of a course
 */  
 

checkSession();

require '../../includes/classes/WS3tableview.php';
require '../../includes/classes/WS3user.php';
require '../../includes/classes/WS3course.php';
require '../../includes/classes/WS3lesson.php';
require '../../includes/classes/WS3module.php';

$user = new WS3_User(); 
$s="";

// must be an admin/headmaster/teacher
if ( isset( $_POST['student_id'] ) )
{
  $user->setUserID( $_POST['student_id'] );
}else // student 
{
  $user->setUserID( $session->userID() );
}

//
if ($user->ID() )
{

  if (isset( $_POST['id'] ) ) // we only want the score for this course id
  {
    $s="AND us.course_id=".$_POST['id'];
  }
  $table=new WS3_TableView('main',400);
  $table->setTitle( 'Listing scores for:'.$user->FullName() );
  $table->addColumnTH('Date');
  $table->addColumnTH('Content');
  $table->addColumnTH('Score');
  $table->setAlternativeRows(true);
  $table->setInfoRow(true);
  
  
  $db=new WS3_Database();

  
// $$TODO to do selective depening on course, lesson etc
 $q="SELECT us.id AS usid , us.date_created AS usda, us.content_id AS uscid,
 us.score AS usscore,
 c.name AS cname, m.name AS mname
  FROM 
  `user_score` AS us
  RIGHT JOIN `content` AS c ON c.id=us.content_id
  RIGHT JOIN `module` AS m ON m.id=c.module_id
  WHERE us.user_id = '".$user->ID()."'
  $s
  ORDER BY us.date_created
  "; 

  
  if ($db->query($q))
  {
    $count = $db->numberRows();
    while ( $db->nextRecord() )
    {
       $table->addRow($db->f('usid'), array(
       'Date' => javaSafeString( $db->f('usda') ),
       'Content' => javaSafeString( $db->f('mname').":".$db->f('cname') ),
       'Score' => javaSafeString( $db->f('usscore') ) 
        )); 
    }
    
    $table->addToInfoRow("<p>Count = $count </p>");
    echo $table->display();
    $message="Listing";
   
  }else{
    $message="Error : Empty list";
  }
}
/** Get menu */
if ( $session->userType()<'3' ){
require '../../includes/menus/topCoursesStudent.php';
}else{
require '../../includes/menus/topGoContent.php';
}

$menu=javaSafeString($menu);
echo "document.getElementById('topmenu').innerHTML='$menu';";

echo "document.getElementById('messages').innerHTML='$message';";
if (W3DEBUG)  $debug=new WS3_Debug();

?>
